package pikes.peak;

import java.util.Map;

import org.springframework.web.servlet.support.RequestContext;

import pikes.html.xhtml.Inline;
import pikes.html.xhtml.PCData;

public class Text implements InlineComponent {

	private RequestProperty<CharSequence> charSequenceProvider = null;

	public Text(final String text) {
		this(new ApplicationContextMessageProvider(text));
	}

	public Text(final RequestProperty<CharSequence> charSequenceProvider) {
		this.charSequenceProvider = charSequenceProvider;
	}

	public Text(final String text, final TextParameters textParameters) {
		this(new ApplicationContextMessageProvider(text, textParameters));
	}

	public final Inline createHtml(Map model, RequestContext requestContext) throws Exception {
		if (charSequenceProvider == null) {
			return null;
		}

		return new PCData(charSequenceProvider.getValue(model, requestContext));
	}

}
